<template>
  <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="200px"  label-position="right">

    <el-form-item label="课程类型" prop="courseStyle">
      <el-radio v-model="ruleForm.courseStyle" label="1" border @change="isChangeShow">通过Excle导入生成员工账号</el-radio>
      <el-radio v-model="ruleForm.courseStyle" label="2" border @change="isChangeShow">个人账号生成</el-radio>
    </el-form-item>
    <!--根据上面的单选框选择出现的组件-->
    <el-form-item label="传入员工信息文件" v-if="isShowAddVideo">
      <el-upload
        style="width: 400px"
        auto-upload="false"
        action="https://jsonplaceholder.typicode.com/posts/"
        :on-preview="handlePreview"
        :on-remove="handleRemove"
        :before-remove="beforeRemove"
        multiple
        :limit="3"
        :on-exceed="handleExceed"
        :file-list="fileList">
        <el-button size="small" type="primary">点击上传</el-button>
        <div slot="tip" class="el-upload__tip">只能上传EXCLE文件</div>
      </el-upload>
    </el-form-item>
    <el-form-item label="个人账号生成" v-if="isShowAddPlace" prop="studyPlace" >
      <el-form label-width="100px"  label-position="right">
        <el-form-item label="员工工号" prop="courseName">
          <el-input v-model="ruleForm.courseName" style="width: 300px"></el-input>
        </el-form-item>
        <el-form-item label="名字" prop="teacherName">
          <el-input v-model="ruleForm.teacherName" style="width: 300px"></el-input>
        </el-form-item>
        <el-form-item label="身份证号" prop="courseIntro">
          <el-input v-model="ruleForm.courseIntro" style="width: 300px"></el-input>
        </el-form-item>
        <el-form-item label="性别" prop="courseStyle">
          <el-radio v-model="ruleForm.courseStyle" label="4" border >男</el-radio>
          <el-radio v-model="ruleForm.courseStyle" label="6" border >女</el-radio>
        </el-form-item>
        <el-form-item label="电子邮箱" prop="courseIntro">
          <el-input v-model="ruleForm.courseIntro" style="width: 300px"></el-input>
        </el-form-item>
        <el-form-item label="电话号码" prop="courseIntro">
          <el-input v-model="ruleForm.courseIntro" style="width: 300px"></el-input>
        </el-form-item>
        <el-form-item label="岗位方向" prop="courseIntro">
          <el-input v-model="ruleForm.courseIntro" style="width: 300px"></el-input>
        </el-form-item>
      </el-form>
    </el-form-item>
    <el-form-item>
      <el-button type="success" @click="submitForm('ruleForm')">立即生成</el-button>
      <el-button @click="resetForm('ruleForm')">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
    import {validateChinese} from "../../tools/validate";

    export default {
        name: "CreateEmpAccount",
      //生成未选择的数据
      data() {

        return {
          //上传文件的控件数据
          fileList: [{name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}, {name: 'food2.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}],
          //控制课程类型子组件的显示
          isShowAddVideo:false,
          isShowAddPlace:false,
          //表单的各个数据项的值
          ruleForm: {
            courseName:'',
            teacherName:'',
            courseIntro:'',
            courseStyle:'',
            examineType:'',
            courseDir:'',
            studyPlace:'',
            testPlace:''

          },
          rules: {
            courseName: [
              { required: true, message: '请输入课程名称', trigger: 'blur' },
              { min: 0, max: 15, message: '长度在 0 到 15 个字符', trigger: 'blur' },
            ],
            teacherName: [
              { required: true, message: '请输入讲师名称', trigger: 'blur' },
              { min: 0, max: 8, message: '长度在 0 到 8 个字符', trigger: 'blur' },
              {validator:validateChinese,trigger: 'blur'}

            ],
            courseIntro:[
              { required: true, message: '请输入课程简介', trigger: 'blur' },
            ],
            courseStyle:[
              { required: true, message: '请选择至少一种类型', trigger: 'blur' },
            ],
            examineType:[
              { required: true, message: '请选择至少一种类型', trigger: 'blur' },
            ],
            courseDir:[
              { required: true, message: '请选择至少一种方向', trigger: 'blur' },
            ],
            studyPlace:[
              { required: true, message: '请填写上课地点', trigger: 'blur' },
            ],
            testPlace:[
              { required: true, message: '请填写考试地点', trigger: 'blur' },
            ],
          },

        };
      },
      methods: {
        //上传文件的控件方法
        handleRemove(file, fileList) {
          console.log(file, fileList);
        },
        handlePreview(file) {
          console.log(file);
        },
        handleExceed(files, fileList) {
          this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
        },
        beforeRemove(file, fileList) {
          return this.$confirm(`确定移除 ${ file.name }？`);
        },
        //控制课程类型子组件是否显示
        isChangeShow(value){
          if(value=="1"){
            this.isShowAddVideo=true;
            this.isShowAddPlace=false;

          }
          if(value=="2"){
            this.isShowAddVideo=false;
            this.isShowAddPlace=true;
          }

        },
        //表单提交
        submitForm(formName) {
          this.$refs[formName].validate((valid) => {
            if (valid) {
              alert('submit!');
            } else {
              console.log('error submit!!');
              return false;
            }
          });
          this.flush();
        },
        //重置表单数据
        resetForm(formName) {
          this.$refs[formName].resetFields();
          this.isShowAddVideo=false;
          this.isShowAddPlace=false;
          this.isShowAddtest=false;
          this.isShowAddtestPlace=false;
        },



      }
    }
</script>

<style scoped>

</style>
